<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<link href="../style/css/manual-zip.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-zip-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
<title>mod_file_cache － Apache 2.2 中文手册 [金步国]</title>
<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?d286c55b63a3c54a1e43d10d4c203e75"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>
</head>
<body><div id="page-header">
<p class="menu"><a href="index.html">模块索引</a> | <a href="directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p><p class="apache">Apache HTTP Server 版本2.2</p><img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="index.html"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
<div id="path"><a href="https://www.apache.org/">Apache</a> &gt; <a href="https://httpd.apache.org/">HTTP Server</a> &gt; <a href="https://httpd.apache.org/docs/">文档</a> &gt; <a href="../index.html">版本2.2</a> &gt; <a href="index.html">模块</a></div>

<div id="translation-info">　　 <a href="../translator_announcement.html#thanks">致谢</a> | 本篇译者：&lt;<a href="../translator_announcement.html#join">虚位以待</a>&gt; | 本篇译稿完成时间：?年?月?日</div>
<div id="page-content"><div id="preamble"><h1>Apache模块 mod_file_cache</h1>

<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="module">
<tr><th><a href="module-dict.html#Description">说明</a></th><td>提供文件描述符缓存支持，从而提高Apache性能</td></tr>
<tr><th><a href="module-dict.html#Status">状态</a></th><td>实验(X)</td></tr>
<tr><th><a href="module-dict.html#ModuleIdentifier">模块名</a></th><td>file_cache_module</td></tr>
<tr><th><a href="module-dict.html#SourceFile">源文件</a></th><td>mod_file_cache.c</td></tr>
</table>
<h3>概述</h3>


    <div class="warning">
      This module should be used with care. You can easily create a broken
      site using <code class="module"><a href="mod_file_cache.html">mod_file_cache</a></code>, so read this document
      carefully.
    </div>

    <p><em>Caching</em> frequently requested files that change very
    infrequently is a technique for reducing server load.
    <code class="module"><a href="mod_file_cache.html">mod_file_cache</a></code> provides two techniques for caching
    frequently requested <em>static</em> files. Through configuration
    directives, you can direct <code class="module"><a href="mod_file_cache.html">mod_file_cache</a></code> to either
    open then <code>mmap()</code> a file, or to pre-open a file and save
    the file's open <em>file handle</em>. Both techniques reduce server
    load when processing requests for these files by doing part of the work
    (specifically, the file I/O) for serving the file when the
    server is started rather than during each request.</p>

    <p>注意：You cannot use this for speeding up CGI programs or
    other files which are served by special content handlers. It
    can only be used for regular files which are usually served by
    the Apache core content handler.</p>

    <p>This module is an extension of and borrows heavily from the
    <code>mod_mmap_static</code> module in Apache 1.3.</p>
</div>
<div class="top"><a href="mod_file_cache.html#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="using" id="using">Using mod_file_cache</a></h2>

    <p><code class="module"><a href="mod_file_cache.html">mod_file_cache</a></code> caches a list of statically
    configured files via <code class="directive"><a href="mod_file_cache.html#mmapfile">MMapFile</a></code>或<code class="directive"><a href="mod_file_cache.html#cachefile">CacheFile</a></code> directives in the main server configuration.</p>

    <p>Not all platforms support both directives. For example, Apache
    on Windows does not currently support the <code class="directive"><a href="mod_file_cache.html#mmapstatic">MMapStatic</a></code> directive, while
    other platforms, like AIX, support both. You will receive an error
    message in the server error log if you attempt to use an
    unsupported directive. If given an unsupported directive, the
    server will start but the file will not be cached. On platforms
    that support both directives, you should experiment with both to
    see which works best for you.</p>

    <h3>MMapFile Directive</h3>

      <p><code class="directive"><a href="mod_file_cache.html#mmapfile">MMapFile</a></code>
      directive of <code class="module"><a href="mod_file_cache.html">mod_file_cache</a></code> maps a list of
      statically configured files into memory through the system call
      <code>mmap()</code>. This system call is available on most modern
      Unix derivates, but not on all. There are sometimes system-specific
      limits on the size and number of files that can be
      <code>mmap()</code>ed, experimentation is probably the easiest way
      to find out.</p>

      <p>This <code>mmap()</code>ing is done once at server start or
      restart, only. So whenever one of the mapped files changes on the
      filesystem you <em>have</em> to restart the server (see the <a href="../stopping.html">Stopping and Restarting</a> documentation).
      To reiterate that point: if the files are modified <em>in place</em>
      without restarting the server you may end up serving requests that
      are completely bogus. You should update files by unlinking the old
      copy and putting a new copy in place. Most tools such as
      <code>rdist</code>和<code>mv</code> do this. The reason why this
      modules doesn't take care of changes to the files is that this check
      would need an extra <code>stat()</code> every time which is a waste
      and against the intent of I/O reduction.</p>


    <h3>CacheFile Directive</h3>

      <p><code class="directive"><a href="mod_file_cache.html#cachefile">CacheFile</a></code>
      directive of <code class="module"><a href="mod_file_cache.html">mod_file_cache</a></code> opens an active
      <em>handle</em>或<em>file descriptor</em> to the file (or files)
      listed in the configuration directive and places these open file
      handles in the cache. When the file is requested, the server
      retrieves the handle from the cache and passes it to the
      <code>sendfile()</code> (or <code>TransmitFile()</code> on Windows),
      socket API.</p>



      <p>This file handle caching is done once at server start or
      restart, only. So whenever one of the cached files changes on
      the filesystem you <em>have</em> to restart the server (see the
      <a href="../stopping.html">Stopping and Restarting</a>
      documentation). To reiterate that point: if the files are
      modified <em>in place</em> without restarting the server you
      may end up serving requests that are completely bogus. You
      should update files by unlinking the old copy and putting a new
      copy in place. Most tools such as <code>rdist</code>和<code>mv</code> do this.</p>


    <div class="note"><h3>注意</h3>
      <p>Don't bother asking for a directive which recursively
      caches all the files in a directory. Try this instead... See the
      <code class="directive"><a href="core.html#include">Include</a></code> directive, and consider
      this command:</p>

      <div class="example"><p><code>
        find /www/htdocs -type f -print \<br />
        | sed -e 's/.*/mmapfile &amp;/' &gt; /www/conf/mmap.conf
      </code></p></div>
    </div>
</div>
<div class="top"><a href="mod_file_cache.html#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="CacheFile" id="CacheFile">CacheFile</a> <a name="cachefile" id="cachefile">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>Cache a list of file handles at startup time</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>CacheFile <var>file-path</var> [<var>file-path</var>] ...</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>实验(X)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_file_cache</td></tr>
</table>
    <p><code class="directive">CacheFile</code> directive opens handles to
    one or more files (given as whitespace separated arguments) and
    places these handles into the cache at server startup
    time. Handles to cached files are automatically closed on a server
    shutdown.  When the files have changed on the filesystem, the
    server should be restarted to to re-cache them.</p>

    <p>Be careful with the <var>file-path</var> arguments: They have
    to literally match the filesystem path Apache's URL-to-filename
    translation handlers create. We cannot compare inodes or other
    stuff to match paths through symbolic links <em>etc.</em>
    because that again would cost extra <code>stat()</code> system
    calls which is not acceptable. This module may or may not work
    with filenames rewritten by <code class="module"><a href="mod_alias.html">mod_alias</a></code>或<code class="module"><a href="mod_rewrite.html">mod_rewrite</a></code>.</p>

    <div class="example"><h3>示例</h3><p><code>
      CacheFile /usr/local/apache/htdocs/index.html
    </code></p></div>

</div>
<div class="top"><a href="mod_file_cache.html#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="MMapFile" id="MMapFile">MMapFile</a> <a name="mmapfile" id="mmapfile">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>Map a list of files into memory at startup time</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MMapFile <var>file-path</var> [<var>file-path</var>] ...</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>实验(X)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_file_cache</td></tr>
</table>
    <p><code class="directive">MMapFile</code> directive maps one or more files
    (given as whitespace separated arguments) into memory at server
    startup time. They are automatically unmapped on a server
    shutdown. When the files have changed on the filesystem at
    least a <code>HUP</code>或<code>USR1</code> signal should be send to
    the server to re-<code>mmap()</code> them.</p>

    <p>Be careful with the <var>file-path</var> arguments: They have
    to literally match the filesystem path Apache's URL-to-filename
    translation handlers create. We cannot compare inodes or other
    stuff to match paths through symbolic links <em>etc.</em>
    because that again would cost extra <code>stat()</code> system
    calls which is not acceptable. This module may or may not work
    with filenames rewritten by <code class="module"><a href="mod_alias.html">mod_alias</a></code>或<code class="module"><a href="mod_rewrite.html">mod_rewrite</a></code>.</p>

    <div class="example"><h3>示例</h3><p><code>
      MMapFile /usr/local/apache/htdocs/index.html
    </code></p></div>

</div>
</div>
<div id="footer">
<p class="apache">本文允许自由的转载、引用、再分发，但必须保留译者署名并注明出处；详见：<a href="../translator_announcement.html#announcement">版权声明</a>。</p>
<p class="menu"><a href="index.html">模块索引</a> | <a href="directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p></div>
</body></html>
